package net.orange.architecture.permission;

import java.util.HashMap;
import java.util.Map;

/**
 * Permission Rule - to judge whether the user can perform the action.
 */
public class PermissionRule {

	public final static Map<String, Boolean> _rule = new HashMap<String, Boolean>();

	static {
		_rule.put(Permission.allow.name() + Permission.forbid.name(),
				Boolean.TRUE);
		_rule.put(Permission.forbid.name() + Permission.allow.name(),
				Boolean.TRUE);
		_rule.put(Permission.allow.name() + Permission.allow.name(),
				Boolean.TRUE);
		_rule.put(Permission.forbid.name() + Permission.forbid.name(),
				Boolean.FALSE);

		_rule.put(Permission.nodefine.name() + Permission.allow.name(),
				Boolean.TRUE);
		_rule.put(Permission.nodefine.name() + Permission.forbid.name(),
				Boolean.FALSE);
		_rule.put(Permission.allow.name() + Permission.nodefine.name(),
				Boolean.TRUE);
		_rule.put(Permission.forbid.name() + Permission.nodefine.name(),
				Boolean.FALSE);

		_rule.put(Permission.nodefine.name() + Permission.nodefine.name(),
				Boolean.TRUE);
	}

	/**
	 * Get permission pair mapping boolean.
	 * 
	 * @param arg0
	 *            The permission 0 - The URL include *
	 * @param arg1
	 *            The permission 1 - The URL of the system define.
	 * @return
	 */
	public static boolean get(Permission arg0, Permission arg1) {
		Boolean can = (Boolean) _rule.get(arg0.name() + arg1.name());
		return can.booleanValue();
	}
}
